//
//  MainViewController.swift
//  sinaweibo
//
//  Created by mac on 15/11/10.
//  Copyright © 2015年 mac. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {

    func composeDidClick() {
        
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        //由于tabBar是只读 不能够直接进行操作 要使用KVC
        let mainTabBar = MainTabBar()
        
        setValue(mainTabBar, forKey: "tabBar")
        
        
         addChildViewControllers()
        
    mainTabBar.composeBtn.addTarget(self, action: "composeDidClick", forControlEvents: .TouchUpInside)
        
    }

    private func addChildViewControllers() {
        
        addChildViewController(HomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(MessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(DiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(ProfileTableViewController(), title: "我", imageName: "tabbar_profile")
        
        
    }
    
    private func addChildViewController(vc: UIViewController,title: String,imageName: String) {
        //实例化导航视图控制器
        let nav = UINavigationController(rootViewController: vc)
        
        vc.title = title
        
        vc.tabBarItem.image = UIImage(named: imageName)
        
        addChildViewController(nav)
    }
    
    
}
